package entityattributenameisunique;

import org.eclipse.emf.ecore.EObject;

import org.eclipse.viatra2.emf.incquery.validation.runtime.Constraint;
import org.eclipse.viatra2.emf.incquery.validation.runtime.ValidationUtil;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BaseGeneratedMatcherFactory;
import entityattributenameisunique.EntityAttributeNameIsUniqueMatch;
import entityattributenameisunique.EntityAttributeNameIsUniqueMatcherFactory;
import entityattributenameisunique.EntityAttributeNameIsUniqueMatcher;

public class EntityAttributeNameIsUniqueConstraint extends Constraint<EntityAttributeNameIsUniqueMatch> {

	private EntityAttributeNameIsUniqueMatcherFactory matcherFactory;

	public EntityAttributeNameIsUniqueConstraint() {
		matcherFactory = new EntityAttributeNameIsUniqueMatcherFactory();
	}

	@Override
	public String getMessage() {
		return "$entity.name$ entity has more than one attribute named $attribute.name$. Entity attribute names should be unique!";
	}

	@Override
	public EObject getLocationObject(EntityAttributeNameIsUniqueMatch signature) {
		Object location = signature.get("entity");
		if(location instanceof EObject){
			return (EObject) location;
		}
		return null;
	}
	
	@Override
	public int getSeverity() {
		return ValidationUtil.getSeverity("error");
	}
	
	@Override
	public BaseGeneratedMatcherFactory<EntityAttributeNameIsUniqueMatch, EntityAttributeNameIsUniqueMatcher> getMatcherFactory() {
		return matcherFactory;
	}
}
